<?php
/**
 * Created by PhpStorm.
 * User: 技术员专用
 * Date: 2019/3/8
 * Time: 15:02
 */
$serv = new Swoole\Server('127.0.0.1', 9501);

$serv->set([
    'worker_num' => 2,    //worker进程数
    'max_request' => 100,
    'daemonize' => false,//是否守护进程
]);

$serv->on('Connect', 'my_connect');
$serv->on('Receive', 'my_receive');
$serv->on('Close', 'my_close');

/**
 * @param $serv
 * @param $fd 客户端链接的唯一表示
 * @param $factor_id 线程ID
 */
function my_connect($serv,$fd,$reactor_id)
{
    echo "Client:$reactor_id-$fd-Connect".PHP_EOL;
}

function my_receive($serv, $fd, $reactor_id, $data)
{
    $serv->send($fd,"Server:$reactor_id-$fd- $data");
}

function my_close($serv, $fd)
{
    echo "Client:Close".PHP_EOL;
}
$serv->start();